﻿using System;
using System.Collections.Generic;
using System.Web;
using PayRoller.Code;
using System.Web.SessionState;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using HySoft.Cash.Business;
using HySoft.Cash.Structure;
using System.Configuration;
using System.Web.Profile;
using System.Data;
using System.Web.UI;
using HySoft.Cash.BaseClass;
using System.Data.SqlClient;
using System.Globalization;
using Huayou.UI.WebControls;

namespace PayRoller.Manage.QuickAdd
{
    public class EmpPay : ParentPage, IRequiresSessionState
    {
        // Fields
        protected Button Button1;
        protected Button Button2;
        protected Button Button3;
        protected Button Button4;
        protected Button Button5;
        protected Button Button6;
        protected CheckBox cbPayment;
        protected DropDownList dlAccount;
        protected DropDownList dlPayment;
        protected DropDownList dlPayment2;
        protected DropDownList dlStatus;
        public DataTable dtBankList;
        public string EmpName = "";
        public string EmpStatus = "";
        protected HtmlForm form1;
        protected HtmlHead Head1;
        protected Label lblTip;
        public string OrgEmpSid = "";
        public int OrgSid;
        protected RadioButtonList RadioButtonList1;
        protected ScriptManager ScriptManager1;
        public string Sid = "";
        protected HtmlTable TABLE1;
        protected HtmlTable TABLE2;
        protected HtmlTable TABLE3;
        protected HtmlTable TABLE4;
        protected HtmlTable TABLE5;
        protected HtmlTable TABLE6;
        protected TextBox txtAccountName;
        protected TextBox txtAccountName2;
        protected TextBox txtAccountNum;
        protected TextBox txtAccountNum2;
        protected TextBox txtAmount;
        protected TextBox txtBankName;
        protected TextBox txtBankName2;
        protected TextBox txtBranch;
        protected TextBox txtBranch2;
        protected TextBox txtBsb;
        protected TextBox txtBsb2;
        protected TextBox txtPaymentAmount;
        protected TextBox txtPaymentDate;
        protected TextBox txtPayReference;
        protected TextBox txtPayReference2;

        // Methods
        //protected void Button1_Click(object sender, EventArgs e)
        //{
        //    if (base.Request["EmpSid"] != null)
        //    {
        //        string str = base.Request["EmpSid"].ToString();
        //        int num = 0;
        //        if (this.cbPayment.Checked)
        //        {
        //            SqlParameter[] commandParameters = new SqlParameter[] { new SqlParameter("@pSid", this.dlPayment.SelectedValue), new SqlParameter("@pEmpSid", str), new SqlParameter("@pPaymentAmount", this.txtAmount.Text), new SqlParameter("@pIsFuture", 1) };
        //            num = SqlHelper.ExecuteNonQuery(ConfigurationManager.AppSettings["SQLConnString"], CommandType.StoredProcedure, "UpdateEmpAmount", commandParameters);
        //        }
        //        else
        //        {
        //            SqlParameter[] parameterArray2 = new SqlParameter[] { new SqlParameter("@pSid", this.dlPayment.SelectedValue), new SqlParameter("@pEmpSid", str), new SqlParameter("@pPaymentAmount", this.txtAmount.Text), new SqlParameter("@pIsFuture", SqlDbType.BigInt) };
        //            num = SqlHelper.ExecuteNonQuery(ConfigurationManager.AppSettings["SQLConnString"], CommandType.StoredProcedure, "UpdateEmpAmount", parameterArray2);
        //        }
        //        if (num > 0)
        //        {
        //            new OpeCommon().AddUptReport(Convert.ToInt32(str), "0006", this.OrgSid);
        //            base.ClientScript.RegisterStartupScript(base.GetType(), "", "<script>alert('Success!');</script>");
        //            this.GetPaymentInfo();
        //        }
        //    }
        //}

        //protected void Button2_Click(object sender, EventArgs e)
        //{
        //    //------20090608将账单日期 转换成数据库中期望的日期---------------------------------------------------
        //    string tempPayDate = this.txtPaymentDate.Text;
        //    string payDateConverted = string.Empty;
        //    Alert alert = new Alert(this.Page);
        //    if (tempPayDate == string.Empty)
        //    {
        //        //alert.Response("please confirm your Date");
        //        return;
        //    }
        //    else
        //    {
        //        string[] temps = tempPayDate.Split('/', '-');
        //        if (temps.Length < 3)
        //        {
        //            //alert.Response("please confirm your Date");
        //            return;
        //        }
        //        else
        //        {
        //            payDateConverted = string.Format("{0}/{1}/{2}", temps[2], temps[1], temps[0]);
        //            try 
        //            {
        //                Convert.ToDateTime(payDateConverted);
        //            }
        //            catch 
        //            {
        //                //alert.Response("please confirm your Date");
        //                return;
        //            }
        //        }
        //    }
        //    //---------------------------------------------------------------------------------------------------

        //    if (((base.Request["EmpSid"] != null) && (this.dlAccount.SelectedValue != "")) && (base.Request["OrgSid"] != null))
        //    {
        //        int empSid = Convert.ToInt32(base.Request["EmpSid"]);
        //        int bankSid = Convert.ToInt32(this.dlAccount.SelectedValue);
        //        int orgSid = Convert.ToInt32(base.Request["OrgSid"]);
        //        try
        //        {
        //            TemppaymentBN tbn = new TemppaymentBN(this.Page);
        //            tbn.QueryEmpSid(empSid);
        //            tbn.QueryBankSid(bankSid);
        //            tbn.QueryInvoiceStatus(PaymentStatuses.NeedDeal);
        //            if (tbn.GetList().Rows.Count <= 0)
        //            {
        //                TemppaymentDT detail = new TemppaymentDT();
        //                detail.EmpSid = empSid;
        //                detail.BankSid = bankSid;
        //                detail.OrgSid = orgSid;
        //                detail.PaymentDate = Convert.ToDateTime(payDateConverted);
        //                detail.PaymentAmount = Convert.ToDecimal(this.txtPaymentAmount.Text);
        //                if (tbn.Add(detail))
        //                {
        //                    new OpeCommon().AddUptReport(empSid, "0002", orgSid);
        //                }
        //                tbn.Dispose();
        //                tbn = null;
        //                base.ClientScript.RegisterStartupScript(base.GetType(), "", "<script>alert('Success!');</script>");
        //                this.txtPaymentDate.Text = this.txtPaymentAmount.Text = "";
        //            }
        //        }
        //        catch (Exception exception)
        //        {
        //            this.lblTip.Text = exception.Message;
        //        }
        //    }
        //}

        //protected void Button3_Click(object sender, EventArgs e)
        //{
        //    TemppaymentBN tbn = new TemppaymentBN(this.Page);
        //    if (tbn.Delete(Convert.ToInt32(this.dlPayment2.SelectedValue)))
        //    {
        //        new OpeCommon().AddUptReport(Convert.ToInt32(base.Request["EmpSid"]), "0005", this.OrgSid);
        //        base.ClientScript.RegisterStartupScript(base.GetType(), "", "<script>alert('Success!');</script>");
        //    }
        //    tbn.Dispose();
        //    tbn = null;
        //    this.GetPaymentInfo();
        //}

        //protected void Button4_Click(object sender, EventArgs e)
        //{
        //    TbankinfoBN obn = new TbankinfoBN(this.Page);
        //    TbankinfoDT detail = new TbankinfoDT();
        //    detail.EmpSid = Convert.ToInt32(base.Request["EmpSid"]);
        //    detail.BankName = this.txtBankName.Text;
        //    detail.Branch = this.txtBranch.Text;
        //    detail.AccountName = this.txtAccountName.Text;
        //    detail.AccountNum = this.txtAccountNum.Text;
        //    detail.Bsb = this.txtBsb.Text;
        //    detail.PayReference = this.txtPayReference.Text;
        //    obn.Add(detail);
        //    obn.Dispose();
        //    obn = null;
        //    this.txtBankName.Text = "";
        //    this.txtBranch.Text = "";
        //    this.txtAccountName.Text = "";
        //    this.txtAccountNum.Text = "";
        //    this.txtBsb.Text = "";
        //    this.txtPayReference.Text = "";
        //    base.ClientScript.RegisterStartupScript(base.GetType(), "", "<script>alert('Success!');</script>");
        //    this.GetBankInfo();
        //}

        //protected void Button5_Click(object sender, EventArgs e)
        //{
        //    TempinfoBN obn = new TempinfoBN(this.Page);
        //    TempinfoDT detail = obn.Get(Convert.ToInt32(base.Request["EmpSid"]));
        //    detail.IsValid = Convert.ToInt32(this.dlStatus.SelectedValue);
        //    obn.Edit(detail);
        //    base.ClientScript.RegisterStartupScript(base.GetType(), "", "<script>alert('Success!');</script>");
        //    obn.Dispose();
        //    obn = null;
        //}

        //protected void Button6_Click(object sender, EventArgs e)
        //{
        //    if (base.Request["BankSid"] != null)
        //    {
        //        TbankinfoBN obn = new TbankinfoBN(this.Page);
        //        TbankinfoDT detail = obn.Get(Convert.ToInt32(base.Request["BankSid"]));
        //        detail.EmpSid = Convert.ToInt32(base.Request["EmpSid"]);
        //        detail.BankName = this.txtBankName2.Text;
        //        detail.Branch = this.txtBranch2.Text;
        //        detail.AccountName = this.txtAccountName2.Text;
        //        detail.AccountNum = this.txtAccountNum2.Text;
        //        detail.Bsb = this.txtBsb2.Text;
        //        detail.PayReference = this.txtPayReference2.Text;
        //        obn.Edit(detail);
        //        obn.Dispose();
        //        obn = null;
        //        base.ClientScript.RegisterStartupScript(base.GetType(), "", "<script>alert('Success!');</script>");
        //        this.dtBankList = this.GetBankList();
        //        this.GetBankInfo();
        //    }
        //}

        //public void GetBankInfo()
        //{
        //    this.dlAccount.Items.Clear();
        //    TbankinfoBN obn = new TbankinfoBN(this.Page);
        //    obn.QueryEmpSid(Convert.ToInt32(base.Request["EmpSid"]));
        //    DataTable list = obn.GetList();
        //    ListItem item = null;
        //    for (int i = 0; i < list.Rows.Count; i++)
        //    {
        //        item = new ListItem(list.Rows[i]["Bsb"].ToString() + " - " + list.Rows[i]["AccountNum"].ToString(), list.Rows[i]["Sid"].ToString());
        //        this.dlAccount.Items.Add(item);
        //    }
        //    obn.Dispose();
        //    obn = null;
        //}

        //public DataTable GetBankList()
        //{
        //    TbankinfoBN obn = new TbankinfoBN(this.Page);
        //    obn.QueryEmpSid(Convert.ToInt32(base.Request["EmpSid"]));
        //    DataTable list = obn.GetList();
        //    obn.Dispose();
        //    obn = null;
        //    return list;
        //}

        //public void GetPaymentInfo()
        //{
        //    this.dlPayment.Items.Clear();
        //    this.dlPayment2.Items.Clear();
        //    TemppaymentBN tbn = new TemppaymentBN(this.Page);
        //    tbn.QueryEmpSid(Convert.ToInt32(base.Request["EmpSid"]));
        //    DataTable list = tbn.GetList();
        //    ListItem item = null;
        //    for (int i = 0; i < list.Rows.Count; i++)
        //    {
        //        string[] strArray = new string[] { "#", (i + 1).ToString(), "[", Convert.ToDateTime(list.Rows[i]["PaymentDate"]).ToString(AppSettings.DateFormatAU), "]", list.Rows[i]["PaymentAmount"].ToString() };
        //        item = new ListItem(string.Concat(strArray), list.Rows[i]["Sid"].ToString());
        //        this.dlPayment.Items.Add(item);
        //        this.dlPayment2.Items.Add(item);
        //    }
        //    this.dlPayment.Items.Insert(0, new ListItem("Please Select Your Payment", "-1"));
        //    this.dlPayment2.Items.Insert(0, new ListItem("Please Select Your Payment", "-1"));

        //    tbn.Dispose();
        //    tbn = null;
        //}

        protected override void OnInit(EventArgs e)
        {
            base.m_ModuleCode = "0006";
            base.CheckLogin(true);
            base.CheckPerm();
            base.OnInit(e);
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            //this.Button1.Attributes.Add("onclick", "return Check1();");
            //this.Button2.Attributes.Add("onclick", "return Check2();");
            //this.Button3.Attributes.Add("onclick", "return Check3();");
            //this.Button4.Attributes.Add("onclick", "return Check4();");
            //if (base.Request["EmpSid"] != null)
            //{
            //    try
            //    {
            //        TempinfoBN obn = new TempinfoBN(this.Page);
            //        TempinfoDT odt = obn.Get(Convert.ToInt32(base.Request["EmpSid"].ToString()));
            //        this.OrgSid = odt.OrgSid;
            //        this.Sid = odt.Sid.ToString();
            //        this.OrgEmpSid = odt.OrgEmpSid;
            //        this.EmpName = odt.EmpName;
            //        this.EmpStatus = odt.IsValid.ToString();
            //        if (this.EmpStatus.Trim().Equals("1"))
            //        {
            //            this.EmpStatus = "Active";
            //        }
            //        else
            //        {
            //            this.EmpStatus = "Terminated";
            //        }
            //        obn.Dispose();
            //        obn = null;
            //    }
            //    catch (Exception exception)
            //    {
            //        this.lblTip.Text = exception.Message;
            //    }
            //    if (!this.Page.IsPostBack)
            //    {
            //        this.GetBankInfo();
            //    }
            //    this.dtBankList = this.GetBankList();
            //}
            //if (!this.Page.IsPostBack)
            //{
            //    this.TABLE1.Visible = this.TABLE2.Visible = this.TABLE3.Visible = this.TABLE4.Visible = this.TABLE5.Visible = this.TABLE6.Visible = false;
            //}
            //if (base.Request["BankSid"] != null)
            //{
            //    this.TABLE6.Visible = true;
            //    this.TABLE2.Visible = this.TABLE3.Visible = this.TABLE1.Visible = this.TABLE5.Visible = this.TABLE4.Visible = false;
            //    if (!this.Page.IsPostBack)
            //    {
            //        TbankinfoBN obn2 = new TbankinfoBN(this.Page);
            //        TbankinfoDT odt2 = obn2.Get(Convert.ToInt32(base.Request["BankSid"]));
            //        this.txtBankName2.Text = odt2.BankName;
            //        this.txtBranch2.Text = odt2.Branch;
            //        this.txtAccountName2.Text = odt2.AccountName;
            //        this.txtAccountNum2.Text = odt2.AccountNum;
            //        this.txtBsb2.Text = odt2.Bsb;
            //        this.txtPayReference2.Text = odt2.PayReference;
            //        obn2.Dispose();
            //        obn2 = null;
            //    }
            //}
        }

        //protected void RadioButtonList1_SelectedIndexChanged(object sender, EventArgs e)
        //{
        //    string selectedValue = this.RadioButtonList1.SelectedValue;
        //    if (selectedValue != null)
        //    {
        //        if (!(selectedValue == "0"))
        //        {
        //            if (!(selectedValue == "1"))
        //            {
        //                if (!(selectedValue == "2"))
        //                {
        //                    if (!(selectedValue == "3"))
        //                    {
        //                        if (!(selectedValue == "4"))
        //                        {
        //                            if (selectedValue == "5")
        //                            {
        //                                this.TABLE6.Visible = true;
        //                                this.TABLE2.Visible = this.TABLE3.Visible = this.TABLE1.Visible = this.TABLE5.Visible = this.TABLE4.Visible = false;
        //                            }
        //                            return;
        //                        }
        //                        this.TABLE5.Visible = true;
        //                        this.TABLE2.Visible = this.TABLE3.Visible = this.TABLE4.Visible = this.TABLE1.Visible = this.TABLE6.Visible = false;
        //                        return;
        //                    }
        //                    this.TABLE4.Visible = true;
        //                    this.TABLE2.Visible = this.TABLE3.Visible = this.TABLE1.Visible = this.TABLE5.Visible = this.TABLE6.Visible = false;
        //                    return;
        //                }
        //                this.GetPaymentInfo();
        //                this.TABLE3.Visible = true;
        //                this.TABLE2.Visible = this.TABLE1.Visible = this.TABLE4.Visible = this.TABLE5.Visible = this.TABLE6.Visible = false;
        //                return;
        //            }
        //        }
        //        else
        //        {
        //            this.GetPaymentInfo();
        //            this.TABLE1.Visible = true;
        //            this.TABLE2.Visible = this.TABLE3.Visible = this.TABLE4.Visible = this.TABLE5.Visible = this.TABLE6.Visible = false;
        //            return;
        //        }
        //        this.TABLE2.Visible = true;
        //        this.TABLE1.Visible = this.TABLE3.Visible = this.TABLE4.Visible = this.TABLE5.Visible = this.TABLE6.Visible = false;
        //    }
        //}

        // Properties
        protected HttpApplication ApplicationInstance
        {
            get
            {
                return this.Context.ApplicationInstance;
            }
        }

        protected DefaultProfile Profile
        {
            get
            {
                return (DefaultProfile)this.Context.Profile;
            }
        }
    }
}
